package com.ysd.lis.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.WkCalcItem;
import com.ysd.lis.mapper.WkCalcItemMapper;
import com.ysd.lis.service.WkCalcItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 绩效考核-核算项目表 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-04-16
 */
@Service
public class WkCalcItemServiceImpl extends ServiceImpl<WkCalcItemMapper, WkCalcItem> implements WkCalcItemService {

    @Autowired
    WkCalcItemMapper wkCalcItemMapper;

    @Override
    public Result getCalcItemList(String keyWord) {
        LambdaQueryWrapper<WkCalcItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(WkCalcItem::getDelFlag, 0)
                .and(StrUtil.isNotEmpty(keyWord), wrapper -> wrapper.like(WkCalcItem::getItemCode, keyWord).or().like(WkCalcItem::getItemName, keyWord));
        List<WkCalcItem> wkCalcItems = wkCalcItemMapper.selectList(lambdaQueryWrapper);
        return Result.succ(1, "查询成功！", wkCalcItems);
    }

    @Override
    public Result addCalcItem(WkCalcItem wkCalcItem) {
        boolean save = this.save(wkCalcItem);
        if (save) {
            return Result.succ(1, "添加成功！", save);
        } else {
            return Result.fail("添加失败");
        }
    }

    @Override
    public Result editCalcItem(WkCalcItem wkCalcItem) {
        boolean save = this.updateById(wkCalcItem);
        if (save) {
            return Result.succ(1, "添加成功！", save);
        } else {
            return Result.fail("添加失败");
        }
    }

    @Override
    public Result deleteCalcItem(List<String> ids) {
        boolean save = this.removeByIds(ids);
        if (save) {
            return Result.succ(1, "添加成功！", save);
        } else {
            return Result.fail("添加失败");
        }
    }
}
